package com.example.bilibili.func;

import com.example.bilibili.entity.Breply;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class RResult {
    private BRObj data;

    public static List<Breply> trans(RResult w) {
        if (w.getData().getReplies() == null) {
            return null;
        }
        List<Breply> list = new ArrayList<>(100);
        for (BReplies wr : w.getData().getReplies()) {
            list.add(trans(wr));
        }
        return list;
    }

    private static Breply trans(BReplies w) {
        Breply breply = new Breply();
        breply.setId(w.getRpid())
                .setVid(w.getOid())
                .setUid(w.getMid())
                .setRoot(w.getRoot())
                .setParent(w.getParent())
                .setCtime(VResult.sdf.format(new Date(w.getCtime() * 1000L)))
                .setLike(w.getLike())
                .setGtime(LocalDateTime.now().format(VResult.dtf))
                .setContent(w.getContent().getMessage());
        return breply;
    }
}

@Data
class BRObj {
    private List<BReplies> replies;
}

@Data
class BReplies {
    private String rpid;
    private String oid;
    private String mid;
    private String root;
    private String parent;
    private int ctime;
    private int like;
    private Content content;
    private List<BReplies> replies;
}

@Data
class Content {
    private String message;
}